from Data import Data
from MetaData import MetaData,MetaDataFactory
import activist.Time

class Alias(Data):
    def __init__(self,expectedid=None):
        super(Alias,self).__init__(expectedid)
        self.command("create")

    command_create_VERSION=0
    def command_create(self,origin,target,creator=None):
        self._createcalled = True
        self._origin = origin
        self._target = target
        
        if creator:
            MetaDataFactory(self,MetaData.Creator,creator)

    def translate(self,path):
        if path == self._origin:
            return self._target
        return None

    def getXML(self):
        return """
<alias class="activist.Alias" id="%(id)s">
  <origin>%(origin)s</origin>
  <target>%(target)s</target>
%(meta)s
</alias>
        """ % { "origin": self._origin,
                "target": self._target,
                "id":self.id(),
                "meta":self.getMetaXML()
                }

    def __str__(self):
        return '<Alias %s %s-->%s >' % (self.id(),self._origin,self._target)
